Flow-Directed Closure Conversion for Typed Languages
نویسندگان
چکیده
This paper presents a novel closure conversion strategy which is part of MLton, a whole-program compiler for Standard ML. Unlike other implementations, MLton performs closure-conversion at an early stage to translate programs to a simply-typed rst-order intermediate language upon which most optimizations are performed. Closure conversion is guided by a global control-ow analysis. Like previous work on defunctionalization, the translation implements closures as elements of datatypes, and uses dispatches at certain call-sites to select the appropriate function to call. However, our use of control-ow analysis leads to a signiicantly improved translation. There are two notable contributions of our work: 1. The translation uses a general ow-analysis framework which includes OCFA. The datatypes in the target language capture the results of the analysis. MLton uses the analysis to insert coercions to translate between diierent representations of a closure to preserve type correctness of the target language program. 2. The translation is practical. Experimental results over a range of benchmarks including large real-world programs such as the compiler itself and the ML-Kit TBE + 97] indicate that the compile-time cost of ow analysis and closure conversion is extremely small, and that the dispatches and coercions inserted by the algorithm are dynamically infrequent. Runtime performance is often more than a factor of two faster than Standard ML of New Jersey.
منابع مشابه
Typed Closure Conversion for Recursively-deened Functions (extended Abstract)
Much recent work on the compilation of statically typed languages such as ML relies on the propagation of type information from source to object code in order to increase the reliability and maintainabilty of the compiler itself and to improve the eeciency and veriiability of generated code. To achieve this the program transformations performed by a compiler must be cast as type-preserving tran...
متن کاملCombining Closure Conversion with Closure Analysis using Algebraic Types
We have developed a new approach to typed closure conversion of higher-order monomorphic languages which also provides a useful uniform framework for closure analysis and subsequent optimization. The approach is based on representing closures as ordinary algebraic data constructors, grouped into algebraic datatypes according to source type; no special type system is needed. Closure applications...
متن کاملA Typed Intermediate Language for Flow-Directed Compilation
We present a typed intermediate language λ for optimizing compilers for function-oriented and polymorphically typed programming languages (e.g., ML). The language λ is a typed lambda calculus with product, sum, intersection, and union types as well as function types annotated with flow labels. A novel formulation of intersection and union types supports encoding flow information in the typed pr...
متن کاملAlpha Conversion in Simply Typed Lambda Calculus
In the usual presentations of simply typed-calculus, it is usual to identify terms that are-convertible. However, this is not at all a practise in most (typed) functional languages, for which simply typed-calculus is a theoretical foundation. Here, ve well known variants of the type system for simply-calculus which work with variable names are presented. Essentially, these formulations diier in...
متن کاملTyped Closure Conversion for Recursively - De ned Functions ( Extended
Much recent work on the compilation of statically typed languages such as ML relies on the propagation of type information from source to object code in order to increase the reliability and maintainabilty of the compiler itself and to improve the e ciency and veri ability of generated code. To achieve this the program transformations performed by a compiler must be cast as type-preserving tran...
متن کامل